#include "StdAfx.h"
#include "BasePageSetup.h"

CBasePageSetup::CBasePageSetup(void)
{
	m_ePaperSize = PAPER_SIZE_A4;
	m_ePaperDire = PAPER_VERTICAL;
	m_pLayerBelongTo = NULL;
}

CBasePageSetup::CBasePageSetup( ePaperSize nSize, ePaperDirection nDire)
{
	m_ePaperSize = nSize;
	m_ePaperDire = nDire;
	m_pLayerBelongTo = NULL;
}



CBasePageSetup::~CBasePageSetup(void)
{
}

void CBasePageSetup::Serialize( CArchive & ar )
{
	if (ar.IsStoring())
	{
		ar << m_ePaperSize;
		ar << m_ePaperDire;
	}
	else
	{
		int nResult(0);
		ar >> nResult;
		m_ePaperSize = (ePaperSize)nResult;
		ar >> nResult;
		m_ePaperDire = (ePaperDirection)nResult;
	}
}

ePaperSize CBasePageSetup::GetPaperSize() const
{
	return m_ePaperSize;
}

ePaperDirection CBasePageSetup::GetPaperDire() const
{
	return m_ePaperDire;
}

CLayer* CBasePageSetup::GetLayerBelongTo() const
{
	return m_pLayerBelongTo;
}

void CBasePageSetup::SetPaperSize(ePaperSize nSize)
{
	m_ePaperSize = nSize;
}

void CBasePageSetup::SetPaperDire( ePaperDirection nDire)
{
	m_ePaperDire = nDire;
}

void CBasePageSetup::SetLayerBelongTo(CLayer* pLayer)
{
	m_pLayerBelongTo = pLayer;
}


double CBasePageSetup::GetSinglePaperWidth()
{
	switch (m_ePaperSize)
	{
	case PAPER_SIZE_A0:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[0][1];
			else
				return g_paperSize[0][0];
		}

	case PAPER_SIZE_A1:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[1][1];
			else
				return g_paperSize[1][0];
		}

	case PAPER_SIZE_A2:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[2][1];
			else
				return g_paperSize[2][0];
		}

	case PAPER_SIZE_A3:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[3][1];
			else
				return g_paperSize[3][0];
		}

	case PAPER_SIZE_A4:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[4][1];
			else
				return g_paperSize[4][0];
		}

	case PAPER_SIZE_A5:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[5][1];
			else
				return g_paperSize[5][0];
		}
	default:
		break;
	}
	return 0;
}

double CBasePageSetup::GetSinglePaperHeight()
{
	switch (m_ePaperSize)
	{
	case PAPER_SIZE_A0:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[0][0];
			else
				return g_paperSize[0][1];
		}

	case PAPER_SIZE_A1:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[1][0];
			else
				return g_paperSize[1][1];
		}

	case PAPER_SIZE_A2:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[2][0];
			else
				return g_paperSize[2][1];
		}

	case PAPER_SIZE_A3:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[3][0];
			else
				return g_paperSize[3][1];
		}

	case PAPER_SIZE_A4:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[4][0];
			else
				return g_paperSize[4][1];
		}

	case PAPER_SIZE_A5:
		{
			if (m_ePaperDire==PAPER_VERTICAL)
				return g_paperSize[5][0];
			else
				return g_paperSize[5][1];
		}
	default:
		break;
	}
	return 0;
}
